// Package driver 模型
package driver

import (
	// "gitee.com/sweetsunnyflower/carpooling-server-go/pkg/logger"

	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/database"
)

// 司机信息表
type Driver struct {
	models.BaseModel
	UserId                uint64            `gorm:"column:user_id" db:"user_id" json:"user_id" form:"user_id"`
	Balance               int64             `gorm:"column:balance;default:0;comment:账号余额，可为负数;" db:"balance" json:"balance" form:"balance"`
	TripsCount            int64             `gorm:"comment:发布的行程总数;" db:"trips_count" json:"trips_count" form:"trips_count"`
	Year                  uint              `gorm:"column:year" db:"year" json:"year" form:"year"`                                                                             //驾龄
	DriverNumber          string            `gorm:"type:varchar(255);comment:行驶证号码;index;" db:"driver_number" json:"driver_number" form:"driver_number"`                       //驾驶证号码
	IdCard                string            `gorm:"type:varchar(20);comment:身份证号码;index;" db:"id_card" json:"id_card" form:"id_card"`                                          //驾驶证类型
	LicenseNumber         string            `gorm:"type:varchar(255)" db:"license_number" json:"license_number" form:"license_number"`                                         //驾驶证号码
	LicenseType           string            `gorm:"type:varchar(255)" db:"license_type" json:"license_type" form:"license_type"`                                               //驾驶证类型
	LicenseExpirationDate models.FormatTime `gorm:"column:license_expiration_date" db:"license_expiration_date" json:"license_expiration_date" form:"license_expiration_date"` //驾驶证过期日期
	EmergencyContactName  string            `gorm:"type:varchar(255)" db:"emergency_contact_name" json:"emergency_contact_name" form:"emergency_contact_name"`                 //紧急联系人姓名
	EmergencyContactPhone string            `gorm:"type:varchar(255)" db:"emergency_contact_phone" json:"emergency_contact_phone" form:"emergency_contact_phone"`              //紧急联系人电话
	models.CommonTimestampsField
}

func (driver *Driver) Create() {
	database.DB.Create(&driver)
}

func (driver *Driver) Save() (rowsAffected int64) {
	result := database.DB.Save(&driver)
	return result.RowsAffected
}

func (driver *Driver) Delete() (rowsAffected int64) {
	result := database.DB.Delete(&driver)
	return result.RowsAffected
}
